/*******************************************************************************
 * Copyright (c) 2014, 2025 Lablicate GmbH.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 * Philip Wenig - initial API and implementation
 *******************************************************************************/
package org.eclipse.chemclipse.chromatogram.msd.filter.supplier.subtract.internal.calculator;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Map;

import org.eclipse.chemclipse.chromatogram.msd.filter.supplier.subtract.calculator.SubtractCalculator;
import org.eclipse.chemclipse.msd.model.core.IScanMSD;
import org.eclipse.chemclipse.msd.model.implementation.CombinedMassSpectrum;
import org.eclipse.chemclipse.msd.model.implementation.Ion;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;

@TestInstance(Lifecycle.PER_CLASS)
public class SubtractCalculator_3_Test {

	private SubtractCalculator subtractCalculator = new SubtractCalculator();;
	private IScanMSD subtractMassSpectrum;
	private IScanMSD targetMassSpectrum;
	private Map<Double, Float> subtractMassSpectrumMap;

	@BeforeAll
	public void setUp() {

		boolean useNominalMasses = true;
		boolean useNormalize = false;

		subtractMassSpectrum = new CombinedMassSpectrum();
		subtractMassSpectrum.addIon(new Ion(18.2, 200));
		subtractMassSpectrum.addIon(new Ion(28.1, 1000));
		subtractMassSpectrum.addIon(new Ion(32.3, 500));

		targetMassSpectrum = new CombinedMassSpectrum();
		targetMassSpectrum.addIon(new Ion(16.1, 2893.3f));
		targetMassSpectrum.addIon(new Ion(18.1, 8484.3f));
		targetMassSpectrum.addIon(new Ion(20.0, 3894.4f));
		targetMassSpectrum.addIon(new Ion(28.1, 57693.0f));
		targetMassSpectrum.addIon(new Ion(32.0, 3894.6f));
		targetMassSpectrum.addIon(new Ion(43.0, 3793.5f));

		subtractMassSpectrumMap = subtractCalculator.getMassSpectrumMap(subtractMassSpectrum, useNominalMasses, useNormalize);
		subtractCalculator.adjustIntensityValues(targetMassSpectrum, subtractMassSpectrumMap, useNominalMasses, useNormalize);
	}

	@Test
	public void testMassSpectrumMap_1() {

		assertEquals(3, subtractMassSpectrumMap.size());
	}

	@Test
	public void testMassSpectrumMap_2() {

		assertEquals(200.0f, subtractMassSpectrumMap.get(18.0), 0);
	}

	@Test
	public void testMassSpectrumMap_3() {

		assertEquals(1000.0f, subtractMassSpectrumMap.get(28.0), 0);
	}

	@Test
	public void testMassSpectrumMap_4() {

		assertEquals(500.0f, subtractMassSpectrumMap.get(32.0), 0);
	}

	@Test
	public void testSubtractedMassSpectrum_1() {

		assertEquals(6, targetMassSpectrum.getNumberOfIons());
	}

	@Test
	public void testSubtractedMassSpectrum_2() {

		assertEquals(2893.3f, targetMassSpectrum.getIon(16.1).getAbundance(), 0);
	}

	@Test
	public void testSubtractedMassSpectrum_3() {

		assertEquals(8284.3f, targetMassSpectrum.getIon(18.1).getAbundance(), 0);
	}

	@Test
	public void testSubtractedMassSpectrum_4() {

		assertEquals(3894.4f, targetMassSpectrum.getIon(20.0).getAbundance(), 0);
	}

	@Test
	public void testSubtractedMassSpectrum_5() {

		assertEquals(3394.6f, targetMassSpectrum.getIon(32.0).getAbundance(), 0);
	}

	@Test
	public void testSubtractedMassSpectrum_6() {

		assertEquals(3793.5f, targetMassSpectrum.getIon(43.0).getAbundance(), 0);
	}

	@Test
	public void testSubtractedMassSpectrum_7() {

		assertEquals(56693.0f, targetMassSpectrum.getIon(28.1).getAbundance(), 0);
	}
}
